package com.lottery.game.runner.v2.utils;

import com.alibaba.fastjson.JSONArray;
import com.lottery.game.common.exception.BaseException;
import com.lottery.game.common.utils.SpringApplicationUtils;

import org.springframework.web.client.RestTemplate;

import lombok.extern.slf4j.Slf4j;

/**
 * @author : yinlin
 * @version : 1.0
 * @date : 2019-03-29 15:00
 * @Description :
 * @Copyright : Copyright (c) 2018
 * @Company : EasySite Technology Chengdu Co. Ltd.
 * @link : com.lottery.game.runner.v3.utils.GameResultGetUtils
 */
@Slf4j
public class GameResultGetUtils {

    /**
     * 获取游戏结果
     * @param urls
     * @return
     */
    public static JSONArray get(String ... urls) {
        if (urls == null || urls.length < 1) {
            throw new BaseException("当前提供的获取游戏结果的URL配置为空，无法获取游戏结果");
        }
        RestTemplate restTemplate = SpringApplicationUtils.getBean(RestTemplate.class);
        for (String url : urls) {
            try {
                return JSONArray.parseArray(restTemplate.getForObject(url, String.class));
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                continue;
            }
        }
        return null;
    }
}
